$(function () {
    $('#summernote').summernote({
        lang: "zh-CN",
        placeholder: '请输入内容',
        minHeight: 600,
        maxHeight: 600,
        focus: true
    });
    var id = $("#id").val();
    if (id) {
        //获取部门信息
        ajax.post("/system/dept/getDeptById", {id: id}, function (res) {
            console.log(res);
            var dept = res.data;
            if (dept.adminIds) {
                data.userIds = dept.adminIds.split(",");
            }
            data.dept = dept
            $("#summernote").summernote("code", data.dept.description);
        });
    }

});

var data = {
    dept: {},
    isLoading: false,
    userList: [],
    userIds: []
};

var methods = {
    //关闭对话框
    closeDialog: function () {
        if (parent) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index)
        } else {
            layer.closeAll();
        }
    },
    //保存内容
    saveContent: function () {
        if (!data.dept.name) {
            layer.alert("请输入部门名称");
            return;
        }
        var content = $("#summernote").summernote("code");
        data.isLoading = true;
        data.dept.description = content;
        if (data.userIds.length > 0) {
            data.dept.userIds = data.userIds.join(",");
        }
        ajax.post("/system/dept/saveOrUpdateDept", data.dept, function (res) {
            data.isLoading = false;
            if (res.code == 1) {
                layer.alert(res.msg, function (index) {
                    layer.close(index);
                    methods.closeDialog();
                })
            } else {
                layer.alert(res.msg);
            }
        })
    }
};
var vm = new Vue({
    data: data, methods: methods, created: function () {
        ajax.post("/system/user/getUserByRole", {role: "2"}, function (res) {
            data.userList = res.data;
        })
    }
}).$mount("#app");
